package personal.study.bl;

import java.sql.Connection;
import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import personal.study.db.DBSupplier;
import personal.study.form.SupplierForm;
import personal.study.util.DBConnection;

public class BLSupplierAction {
	private static Log log = LogFactory.getLog(BLSupplierAction.class);

	public Collection<SupplierForm> querySupplier(String conditions, int currentPage, int rowsPerPage) throws Exception{
		Collection<SupplierForm> col = null;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBSupplier dbSupplier = new DBSupplier();
			col = dbSupplier.querySupplier(con, conditions, currentPage, rowsPerPage);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		
		return col;
	}
	
	public int getCount(String conditions) throws Exception{
		int count = 0;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			count = new DBSupplier().getCount(con, conditions);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return count;
	}
	
	public boolean insert(SupplierForm supplierForm) throws Exception{
		boolean result = false;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBSupplier dbSupplier = new DBSupplier();
			result = dbSupplier.insert(con, supplierForm);
		}catch(Exception e){
			log.error(e.getMessage());
			result = false;
		}
		return result;
	}
	
	public SupplierForm findByPrimaryKey(String supplierCode) throws Exception{
		SupplierForm supplierForm = null;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBSupplier dbSupplier = new DBSupplier();
			supplierForm = dbSupplier.findByPrimaryKey(con, supplierCode);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return supplierForm;
	}
	
	public boolean update(SupplierForm supplierForm) throws Exception {
		boolean result = false;
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBSupplier dbSupplier = new DBSupplier();
			result = dbSupplier.update(con, supplierForm);
		}catch(Exception e){
			log.error(e.getMessage());
			result = false;
		}
		
		return result;
	}
	
	public void deleteByPrimaryKey(String supplierCode) throws Exception{
		Connection con = null;
		try{
			con = DBConnection.getCon();
			DBSupplier dbSupplier = new DBSupplier();
			dbSupplier.delete(con, supplierCode);
		}catch(Exception e){
			log.error(e.getMessage());
		}
	}
}
